#include <iostream>
#include <vector>

using namespace std;

// 1432. 改变一个整数能得到的最大差值
// https://leetcode.cn/problems/max-difference-you-can-get-from-changing-an-integer/description/?envType=daily-question&envId=2025-06-15

class Solution {
public:
    int maxDiff(int num) {
        string maxNum = to_string(num);
        string minNum = maxNum;
        char changeCh = 'a';
        for (char &ch : maxNum)
        {
            if(ch != '9' && changeCh == 'a'){
                changeCh = ch;
            }
            if(ch == changeCh){
                ch = '9';
            }
        }
        changeCh = minNum[0];
        string minNum1 = minNum;
        for (char &ch : minNum)
        {
            if(ch == changeCh){
                ch = '1';
            }
        }

        if(minNum.size() > 1){
            char changeCh1 = 'a';
            for (char &ch : minNum1)
            {
                if(ch > changeCh && changeCh1 == 'a'){
                    changeCh1 = ch;
                }
                if(ch == changeCh1){
                    ch = '0';
                }
            }
        }

        return stoi(maxNum) - min(stoi(minNum), stoi(minNum1));
    }
};

int main()
{
    return 0;
}